package com.menu;

import com.company.SortArray;

import java.io.IOException;
import java.util.Scanner;

public class SortArrayMenu {

    public void sortMenu() throws IOException {

        boolean flag = true;
        while (flag){
            System.out.println("\\n请选择排序的方法：\\n");
            System.out.println("\t1.快速排序");
            System.out.println("\t2.选择排序\\n");
            System.out.println("\t3.希尔排序\\n");
            System.out.println("\t4.冒泡排序\\n");
            System.out.println("\t5.插入排序\\n");
            System.out.println("\t0.退出\\n");
            System.out.print("\t请选择：");

            int sc = -1;
            try{
                Scanner scanner = new Scanner(System.in);
                sc = scanner.nextInt();
            }catch (Exception e) {
                System.out.println("错误有误,请重新输入");
            }
            switch (sc){
                case 1:{
                    runQuickSort();
                    break;
                }
                case 2:{
                    runSelectSort();;
                    break;
                }
                case 3:{
                    runShellSort();
                    break;
                }
                case 4:{
                    runBubbleSort_v2();
                    break;
                }case 5:{
                    runInsertSort();
                    break;
                }
                case 0:{
                    flag = false;
                    break;
                }
                default:{
                    System.out.println("输入有误，请重新输入：");
                    break;
                }
            }
        }




    }

    public void runSelectSort() throws IOException {
        long totalMilliSeconds = System.currentTimeMillis();
        System.out.println("正在排序中，此过程大概持续14s,请耐心等待！！！");
        SortArray so = new SortArray();
        so.selectSort();
        long totalMilliSeconds02 = System.currentTimeMillis();
        System.out.print("选择排序所用时间：" );
        System.out.println(totalMilliSeconds02 - totalMilliSeconds);
        System.out.println("选择排序完毕！！");


    }

    public void runQuickSort() throws IOException {
        long totalMilliSeconds = System.currentTimeMillis();
        SortArray so = new SortArray();
        so.quickSort();
        long totalMilliSeconds02 = System.currentTimeMillis();
        System.out.print("快速排序所用时间：" );
        System.out.println(totalMilliSeconds02 - totalMilliSeconds);
        System.out.println("快速排序完毕");

    }

    public void runBubbleSort_v2() throws IOException {
        long totalMilliSeconds = System.currentTimeMillis();
        SortArray so = new SortArray();
        System.out.println("正在冒泡排序中，此过程大概持续10s,请耐心等待！！！");
        so.bubbleSort_v2();
        long totalMilliSeconds02 = System.currentTimeMillis();
        System.out.print("冒泡排序所用时间：" );
        System.out.println(totalMilliSeconds02 - totalMilliSeconds);
        System.out.println("冒泡排序完毕！！");
    }

    public void runShellSort() throws IOException {
        long totalMilliSeconds = System.currentTimeMillis();
        SortArray so = new SortArray();
        so.shellSort();
        long totalMilliSeconds02 = System.currentTimeMillis();
        System.out.print("希尔排序所用时间：" );
        System.out.println(totalMilliSeconds02 - totalMilliSeconds);
        System.out.println("希尔排序完毕");
    }

    public void runInsertSort() throws IOException {
        long totalMilliSeconds = System.currentTimeMillis();
        SortArray so = new SortArray();
        System.out.println("正在排序中，此过程大概持续5s,请耐心等待！！！");
        so.insertSort();
        long totalMilliSeconds02 = System.currentTimeMillis();
        System.out.print("插入排序所用时间：" );
        System.out.println(totalMilliSeconds02 - totalMilliSeconds);
        System.out.println("插入排序完毕");
    }

}
